/*
 * @lc app=leetcode.cn id=500 lang=javascript
 *
 * [500] 键盘行
 */

// @lc code=start
/**
 * @param {string[]} words
 * @return {string[]}
 */
var findWords = function(words) {
  let ids = '23321222122233111121131313';
  let list = [];
  for (const word of words) {
    let isValid = true;
    let first = ids[word.toLowerCase()[0].charCodeAt() - 'a'.charCodeAt()];
    for (const ch of word.toLowerCase().split('')) {
      isValid = first === ids[ch.charCodeAt() - 'a'.charCodeAt()]
      if (!isValid) {
        break;
      }
    }

    if (isValid) {
      list.push(word);
    }
  }
  return list;
};
// @lc code=end

